#pragma once
#include "IndexBuffer.h"
#include "VertexBuffer.h"
#include "Mesh.h"
#include "SubModelMesh.h"

namespace Graphics{
	class Model : public Core::MemTrack{
	public:
		Model(std::string &name):m_id(-1),m_name(name),m_vertBufferId(0),m_activeVertBuffer(-1),m_controllerId(-1),m_transparencyCheck(false){}
		~Model();

		void render(RenderContext* context, std::list<unsigned int> &instances);
		void render(RenderContext* context, std::list<unsigned int> &instances, std::list<unsigned int>& subMeshes);

		void addInstance(boost::shared_ptr<Mesh> mesh);

		void removeInstance(boost::shared_ptr<Mesh> mesh);

		void setIndBuffer(boost::shared_ptr<IndexBuffer> buffer) { m_indBuffer = buffer; }

		unsigned int addVertexBuffer(VertexBufferPtr vertBuffer);
		VertexBufferPtr getVertexBuffer(unsigned int id);

		IndexBufferPtr getIndexBuffer() { return m_indBuffer; }
		std::vector<SubModelMeshPtr>& getSubMeshList() { return m_subMeshes; }

		void addSubModel(SubModelMeshPtr subModel) { m_subMeshes.push_back(subModel); }
		void addController(unsigned int id) { m_controllerId = id; }

		std::string& getName() { return m_name; }
		int getControllerId() { return m_controllerId; }
		std::map<unsigned int, boost::shared_ptr<Mesh>>& getInstanceMap() { return m_meshes; }
	private:
		int m_id;
		std::string m_name;
		unsigned int m_vertBufferId;
		int m_controllerId;
		bool m_transparencyCheck;

		boost::shared_ptr<IndexBuffer> 	m_indBuffer;

		std::map<unsigned int, VertexBufferPtr> m_vertBuffers;
		std::vector<SubModelMeshPtr> m_subMeshes;

		std::map<unsigned int, boost::shared_ptr<Mesh>> m_meshes;

		int m_activeVertBuffer;

		friend class RenderSystem;
	};

	typedef boost::shared_ptr<Model> ModelPtr;
}